package com.example.mvpdemo.util;

import com.example.mvpdemo.R;
import com.example.mvpdemo.base.App;

import java.math.BigDecimal;

/**
 * @author:created by njb
 * 时间:2019/3/8 14 42
 * 描述:
 */
public class StringUtils {
        /**
         * float 转成一位小数
         *
         * @param value
         * @return
         */
        public static String floatFormat(float value) {
            BigDecimal bd = new BigDecimal(value);
            bd = bd.setScale(1, BigDecimal.ROUND_HALF_DOWN);
            return bd.toString();
        }

        /**
         * 空字符
         */
        public static final String EMPTY = "";

        /**
         * <p>Checks if a CharSequence is empty ("") or null.</p>
         *
         * <pre>
         * StringUtils.isEmpty(null)      = true
         * StringUtils.isEmpty("")        = true
         * StringUtils.isEmpty(" ")       = false
         * StringUtils.isEmpty("bob")     = false
         * StringUtils.isEmpty("  bob  ") = false
         * </pre>
         *
         * <p>NOTE: This method changed in Lang version 2.0.
         * It no longer trims the CharSequence.
         * That functionality is available in isBlank().</p>
         *
         * @param cs  the CharSequence to check, may be null
         * @return {@code true} if the CharSequence is empty or null
         * @since 3.0 Changed signature from isEmpty(String) to isEmpty(CharSequence)
         */
        public static boolean isEmpty(CharSequence cs) {
            return cs == null || cs.length() == 0;
        }

        /**
         * 判断字符串是否为null或全为空格
         *
         * @param s 待校验字符串
         * @return {@code true}: null或全空格<br> {@code false}: 不为null且不全空格
         */
        public static boolean isSpace(String s) {
            return (s == null || s.trim().length() == 0);
        }


        /**
         * <p>Checks if a CharSequence is not empty ("") and not null.</p>
         *
         * <pre>
         * StringUtils.isNotEmpty(null)      = false
         * StringUtils.isNotEmpty("")        = false
         * StringUtils.isNotEmpty(" ")       = true
         * StringUtils.isNotEmpty("bob")     = true
         * StringUtils.isNotEmpty("  bob  ") = true
         * </pre>
         *
         * @param cs  the CharSequence to check, may be null
         * @return {@code true} if the CharSequence is not empty and not null
         * @since 3.0 Changed signature from isNotEmpty(String) to isNotEmpty(CharSequence)
         */
        public static boolean isNotEmpty(CharSequence cs) {
            return !StringUtils.isEmpty(cs);
        }

    public static String getPermissionName(String per) {
        switch (per) {
            case "android.permission.WRITE_EXTERNAL_STORAGE":
            case "android.permission" +
                    ".READ_EXTERNAL_STORAGE":
                return App.getContext().getString(R.string.file_permission);
        }
        return "";
    }
}
